{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "3da4f293",
   "metadata": {},
   "source": [
    "## 1. APP U本位合约行情-交易规则信息函数总览"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7459f345",
   "metadata": {},
   "source": [
    "|方法|解释|\n",
    "|:---|:---|\n",
    "|get_exchangeInfo|以缓存的方式获取一个产品的交易规则与交易对|\n",
    "|get_exchangeInfos|以缓存的方式获取全部产品的交易规则与交易对|\n",
    "|get_symbols_trading_on|获取可以交易的产品列表|\n",
    "|get_symbols_trading_off|获取不可交易的产品列表|\n",
    "|get_symbols_all|获取全部的产品列表|"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "361e95b0",
   "metadata": {},
   "source": [
    "## 2. 模型实例化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "40948dc7",
   "metadata": {},
   "outputs": [],
   "source": [
    "from binance_interface.app import BinanceUM\n",
    "from binance_interface.app.utils import eprint"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "1af7e0be",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 转发：需搭建转发服务器，可参考：https://github.com/pyted/binance_resender\n",
    "proxy_host = None\n",
    "key = 'xxxx'\n",
    "secret = 'xxxx'\n",
    "\n",
    "binanceUM = BinanceUM(\n",
    "    key=key, secret=secret,\n",
    "    proxy_host=proxy_host\n",
    ")\n",
    "market = binanceUM.market"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f9d31f40",
   "metadata": {},
   "source": [
    "## 3. 以缓存的方式获取一个产品的交易规则与交易对 get_exchangeInfo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "8033068b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': {'symbol': 'BTCUSDT',\n",
      "          'pair': 'BTCUSDT',\n",
      "          'contractType': 'PERPETUAL',\n",
      "          'deliveryDate': 4133404800000,\n",
      "          'onboardDate': 1569398400000,\n",
      "          'status': 'TRADING',\n",
      "          'maintMarginPercent': '2.5000',\n",
      "          'requiredMarginPercent': '5.0000',\n",
      "          'baseAsset': 'BTC',\n",
      "          'quoteAsset': 'USDT',\n",
      "          'marginAsset': 'USDT',\n",
      "          'pricePrecision': 2,\n",
      "          'quantityPrecision': 3,\n",
      "          'baseAssetPrecision': 8,\n",
      "          'quotePrecision': 8,\n",
      "          'underlyingType': 'COIN',\n",
      "          'underlyingSubType': ['PoW'],\n",
      "          'settlePlan': 0,\n",
      "          'triggerProtect': '0.0500',\n",
      "          'liquidationFee': '0.012500',\n",
      "          'marketTakeBound': '0.05',\n",
      "          'maxMoveOrderLimit': 10000,\n",
      "          'filters': [{'maxPrice': '4529764', 'tickSize': '0.10', 'filterType': 'PRICE_FILTER', 'minPrice': '556.80'},\n",
      "                      {'stepSize': '0.001', 'minQty': '0.001', 'filterType': 'LOT_SIZE', 'maxQty': '1000'},\n",
      "                      {'maxQty': '120', 'minQty': '0.001', 'stepSize': '0.001', 'filterType': 'MARKET_LOT_SIZE'},\n",
      "                      {'limit': 200, 'filterType': 'MAX_NUM_ORDERS'},\n",
      "                      {'limit': 10, 'filterType': 'MAX_NUM_ALGO_ORDERS'},\n",
      "                      '......'],\n",
      "          'orderTypes': ['LIMIT', 'MARKET', 'STOP', 'STOP_MARKET', 'TAKE_PROFIT', '......'],\n",
      "          'timeInForce': ['GTC', 'IOC', 'FOK', 'GTX', 'GTD'],\n",
      "          'filter': {'PRICE_FILTER': {'maxPrice': '4529764',\n",
      "                                      'tickSize': '0.10',\n",
      "                                      'filterType': 'PRICE_FILTER',\n",
      "                                      'minPrice': '556.80'},\n",
      "                     'LOT_SIZE': {'stepSize': '0.001', 'minQty': '0.001', 'filterType': 'LOT_SIZE', 'maxQty': '1000'},\n",
      "                     'MARKET_LOT_SIZE': {'maxQty': '120',\n",
      "                                         'minQty': '0.001',\n",
      "                                         'stepSize': '0.001',\n",
      "                                         'filterType': 'MARKET_LOT_SIZE'},\n",
      "                     'MAX_NUM_ORDERS': {'limit': 200, 'filterType': 'MAX_NUM_ORDERS'},\n",
      "                     'MAX_NUM_ALGO_ORDERS': {'limit': 10, 'filterType': 'MAX_NUM_ALGO_ORDERS'},\n",
      "                     '...': '......'}},\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "exchangeInfo_result = market.get_exchangeInfo(symbol='BTCUSDT')\n",
    "eprint(exchangeInfo_result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fa987f82",
   "metadata": {},
   "source": [
    "## 4. 以缓存的方式获取全部产品的交易规则与交易对 get_exchangeInfos"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "29dfe80e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': {'timezone': 'UTC',\n",
      "          'serverTime': 1706112011203,\n",
      "          'futuresType': 'U_MARGINED',\n",
      "          'rateLimits': [{'rateLimitType': 'REQUEST_WEIGHT', 'interval': 'MINUTE', 'intervalNum': 1, 'limit': 2400},\n",
      "                         {'rateLimitType': 'ORDERS', 'interval': 'MINUTE', 'intervalNum': 1, 'limit': 1200},\n",
      "                         {'rateLimitType': 'ORDERS', 'interval': 'SECOND', 'intervalNum': 10, 'limit': 300}],\n",
      "          'exchangeFilters': [],\n",
      "          'assets': [{'asset': 'USDT', 'marginAvailable': True, 'autoAssetExchange': '-10000'},\n",
      "                     {'asset': 'BTC', 'marginAvailable': True, 'autoAssetExchange': '-0.10000000'},\n",
      "                     {'asset': 'BNB', 'marginAvailable': True, 'autoAssetExchange': '-10'},\n",
      "                     {'asset': 'ETH', 'marginAvailable': True, 'autoAssetExchange': '-5'},\n",
      "                     {'asset': 'XRP', 'marginAvailable': True, 'autoAssetExchange': '0'},\n",
      "                     '......'],\n",
      "          'symbols': [{'symbol': 'BTCUSDT',\n",
      "                       'pair': 'BTCUSDT',\n",
      "                       'contractType': 'PERPETUAL',\n",
      "                       'deliveryDate': 4133404800000,\n",
      "                       'onboardDate': 1569398400000,\n",
      "                       '...': '......'},\n",
      "                      {'symbol': 'ETHUSDT',\n",
      "                       'pair': 'ETHUSDT',\n",
      "                       'contractType': 'PERPETUAL',\n",
      "                       'deliveryDate': 4133404800000,\n",
      "                       'onboardDate': 1569398400000,\n",
      "                       '...': '......'},\n",
      "                      {'symbol': 'BCHUSDT',\n",
      "                       'pair': 'BCHUSDT',\n",
      "                       'contractType': 'PERPETUAL',\n",
      "                       'deliveryDate': 4133404800000,\n",
      "                       'onboardDate': 1569398400000,\n",
      "                       '...': '......'},\n",
      "                      {'symbol': 'XRPUSDT',\n",
      "                       'pair': 'XRPUSDT',\n",
      "                       'contractType': 'PERPETUAL',\n",
      "                       'deliveryDate': 4133404800000,\n",
      "                       'onboardDate': 1569398400000,\n",
      "                       '...': '......'},\n",
      "                      {'symbol': 'EOSUSDT',\n",
      "                       'pair': 'EOSUSDT',\n",
      "                       'contractType': 'PERPETUAL',\n",
      "                       'deliveryDate': 4133404800000,\n",
      "                       'onboardDate': 1569398400000,\n",
      "                       '...': '......'},\n",
      "                      '......']},\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "exchangeInfos_result = market.get_exchangeInfos()\n",
    "eprint(exchangeInfos_result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3a8bceee",
   "metadata": {},
   "source": [
    "## 5. 获取可以交易的产品列表 get_symbols_trading_on"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "9fc5956d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': ['BTCUSDT',\n",
      "          'ETHUSDT',\n",
      "          'BCHUSDT',\n",
      "          'XRPUSDT',\n",
      "          'EOSUSDT',\n",
      "          'LTCUSDT',\n",
      "          'TRXUSDT',\n",
      "          'ETCUSDT',\n",
      "          'LINKUSDT',\n",
      "          'XLMUSDT',\n",
      "          'ADAUSDT',\n",
      "          'XMRUSDT',\n",
      "          'DASHUSDT',\n",
      "          'ZECUSDT',\n",
      "          'XTZUSDT',\n",
      "          'BNBUSDT',\n",
      "          'ATOMUSDT',\n",
      "          'ONTUSDT',\n",
      "          'IOTAUSDT',\n",
      "          'BATUSDT',\n",
      "          'VETUSDT',\n",
      "          'NEOUSDT',\n",
      "          'QTUMUSDT',\n",
      "          'IOSTUSDT',\n",
      "          'THETAUSDT',\n",
      "          'ALGOUSDT',\n",
      "          'ZILUSDT',\n",
      "          'KNCUSDT',\n",
      "          'ZRXUSDT',\n",
      "          'COMPUSDT',\n",
      "          '......'],\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "symbols_trading_on_result = market.get_symbols_trading_on()\n",
    "eprint(symbols_trading_on_result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cc2ae634",
   "metadata": {},
   "source": [
    "## 6. 获取不可交易的产品列表 get_symbols_trading_off"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "506ad36c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': ['SRMUSDT',\n",
      "          'HNTUSDT',\n",
      "          'TOMOUSDT',\n",
      "          'CVCUSDT',\n",
      "          'BTSUSDT',\n",
      "          'BTCSTUSDT',\n",
      "          'SCUSDT',\n",
      "          'RAYUSDT',\n",
      "          'FTTUSDT',\n",
      "          'COCOSUSDT'],\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "symbols_trading_off_result = market.get_symbols_trading_off()\n",
    "eprint(symbols_trading_off_result) "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cc05b8b8",
   "metadata": {},
   "source": [
    "## 7. 获取全部的产品列表 get_symbols_all"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "7ee5ed1e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': ['BTCUSDT',\n",
      "          'ETHUSDT',\n",
      "          'BCHUSDT',\n",
      "          'XRPUSDT',\n",
      "          'EOSUSDT',\n",
      "          'LTCUSDT',\n",
      "          'TRXUSDT',\n",
      "          'ETCUSDT',\n",
      "          'LINKUSDT',\n",
      "          'XLMUSDT',\n",
      "          'ADAUSDT',\n",
      "          'XMRUSDT',\n",
      "          'DASHUSDT',\n",
      "          'ZECUSDT',\n",
      "          'XTZUSDT',\n",
      "          'BNBUSDT',\n",
      "          'ATOMUSDT',\n",
      "          'ONTUSDT',\n",
      "          'IOTAUSDT',\n",
      "          'BATUSDT',\n",
      "          'VETUSDT',\n",
      "          'NEOUSDT',\n",
      "          'QTUMUSDT',\n",
      "          'IOSTUSDT',\n",
      "          'THETAUSDT',\n",
      "          'ALGOUSDT',\n",
      "          'ZILUSDT',\n",
      "          'KNCUSDT',\n",
      "          'ZRXUSDT',\n",
      "          'COMPUSDT',\n",
      "          '......'],\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "symbols_all_result = market.get_symbols_all()\n",
    "eprint(symbols_all_result)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
